package com.ruoyi.web.controller.wq;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.wq.domain.WqUserGame;
import com.ruoyi.wq.domain.vo.WqUserGameVO;
import com.ruoyi.wq.service.IWqUserGameService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.service.UserGameService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 我的组队Controller
 * 
 * @author ruoyi
 * @date 2023-05-27
 */
@RestController
@RequestMapping("/wq/userGame")
public class WqUserGameController extends BaseController {

    @Autowired
    private IWqUserGameService wqUserGameService;
    
    @Autowired
    private UserGameService userGameService;

    /**
     * 查询我的组队列表
     */
    @GetMapping("/list")
    public TableDataInfo list(WqUserGameVO wqUserGame){
    	TableDataInfo info = wqUserGameService.getPageList(wqUserGame);
        return info;
    }

    /**
     * 导出我的组队列表
     */
    @PreAuthorize("@ss.hasPermi('wq:userGame:export')")
    @Log(title = "我的组队", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WqUserGame wqUserGame)
    {
        List<WqUserGame> list = wqUserGameService.selectWqUserGameList(wqUserGame);
        ExcelUtil<WqUserGame> util = new ExcelUtil<WqUserGame>(WqUserGame.class);
        util.exportExcel(response, list, "我的组队数据");
    }

    /**
     * 获取我的组队详细信息
     */
    @PreAuthorize("@ss.hasPermi('wq:userGame:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(wqUserGameService.selectWqUserGameById(id));
    }

    /**
     * 新增我的组队
     */
    @PreAuthorize("@ss.hasPermi('wq:userGame:add')")
    @Log(title = "我的组队", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WqUserGame wqUserGame)
    {
        return toAjax(wqUserGameService.insertWqUserGame(wqUserGame));
    }

    /**
     * 踢出我的组队
     */
    @PostMapping("/removeHome")
    public AjaxResult edit(@RequestBody WqUserGameVO wqUserGame){
    	userGameService.removeHome(wqUserGame);
        return AjaxResult.success();
    }

    /**
     * 删除我的组队
     */
    @PreAuthorize("@ss.hasPermi('wq:userGame:remove')")
    @Log(title = "我的组队", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(wqUserGameService.deleteWqUserGameByIds(ids));
    }
}
